﻿using ASP;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public partial class Admin_Admin_ShopSendOrderView : Admin, IRequiresSessionState
{
    private Shop_DeliverItem _DItem = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Shop_DeliverItem m_DItem
    {
        get
        {
            Shop_DeliverItem dItem;
            if (this._DItem == null)
            {
                this._DItem = new Shop_DeliverItem(this.conn);
                dItem = this._DItem;
            }
            else
            {
                dItem = this._DItem;
            }
            return dItem;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(21))
        {
            base.WriteRightErrMsg();
        }
        this.TxtBeginDate.Attributes.Add("onfocus", "SelectDate(" + this.TxtBeginDate.UniqueID + ",'yyyy-MM-dd');");
        this.TxtEndDate.Attributes.Add("onfocus", "SelectDate(" + this.TxtEndDate.UniqueID + ",'yyyy-MM-dd');");
        this.BindList();
    }
    protected void BindList()
    {
        this.AddUserDropDownList();
        int inputerID = Convert.ToInt32(this.UserDropDownList.SelectedValue);
        int deliverType = Convert.ToInt32(this.DropDeliverType.SelectedValue);
        string value = this.TxtBeginDate.Text.Trim();
        string value2 = this.TxtEndDate.Text.Trim();
        if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(value2))
        {
            if (Convert.ToDateTime(value) > Convert.ToDateTime(value2))
            {
                this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
            }
        }
        string beginDate = "";
        if (this.TxtBeginDate.Text == "")
        {
            beginDate = "2006/01/01";
        }
        else
        {
            try
            {
                Convert.ToDateTime(this.TxtBeginDate.Text);
                beginDate = this.TxtBeginDate.Text;
            }
            catch
            {
                this.TxtBeginDate.Text = "";
                beginDate = "2006/01/01";
            }
        }
        string endDate = "";
        if (this.TxtEndDate.Text == "")
        {
            endDate = DateTime.Now.ToShortDateString();
        }
        else
        {
            try
            {
                Convert.ToDateTime(this.TxtEndDate.Text);
                endDate = this.TxtEndDate.Text;
            }
            catch
            {
                this.TxtEndDate.Text = "";
                endDate = DateTime.Now.ToShortDateString();
            }
        }
        this.GridView3.DataSource = this.m_DItem.GetDeliverByUserNameInputerBegindDateEndDateType(inputerID, this.TxtHanderName.Text, this.TxtUserName.Text, beginDate, endDate, deliverType);
        this.GridView3.DataBind();
    }
    protected void AddUserDropDownList()
    {
        if (this.TextUserName.Text != "")
        {
            IDbDataParameter dbDataParameter = this.conn.CreateParameter("@UserName", DbType.String, this.TextUserName.Text);
            IDataReader reader = this.conn.GetReader("Select UserID From [HL_User] Where ([UserName] = @UserName)", new IDbDataParameter[]
			{
				dbDataParameter
			});
            int num = 0;
            if (reader.Read())
            {
                num = Convert.ToInt32(reader["UserID"]);
                reader.Close();
                reader.Dispose();
                if (num != 0)
                {
                    foreach (ListItem listItem in this.UserDropDownList.Items)
                    {
                        if (listItem.Text.Trim() == this.TextUserName.Text.Trim())
                        {
                            return;
                        }
                    }
                    ListItem item = new ListItem(this.TextUserName.Text, num.ToString());
                    this.UserDropDownList.Items.Add(item);
                    this.UserDropDownList.SelectedValue = num.ToString();
                }
            }
            else
            {
                reader.Close();
                reader.Dispose();
            }
        }
    }
    protected void GridView3_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow gridViewRow in this.GridView3.Rows)
        {
            if (!base.admin.CheckAdminPower(21))
            {
                gridViewRow.Cells[10].Enabled = false;
            }
            if (gridViewRow.Cells[0].Text != "")
            {
                gridViewRow.Cells[0].Text = DateTime.Parse(gridViewRow.Cells[0].Text).ToShortDateString();
            }
            if (gridViewRow.Cells[1].Text.Trim() == "0")
            {
                gridViewRow.Cells[1].Text = "发货";
            }
            if (gridViewRow.Cells[1].Text.Trim() == "1")
            {
                gridViewRow.Cells[1].Text = "退货";
            }
        }
    }
    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
    protected void My_DeleteDeliverItem(object sender, CommandEventArgs e)
    {
        int num = 0;
        try
        {
            num = int.Parse(e.CommandName.ToString());
        }
        catch
        {
            this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
        }
        if (num > 0)
        {
            if (this.m_DItem.DeleteDeliverItem(num.ToString()))
            {
                this.GridView3.DataBind();
            }
        }
    }
    protected void GridView3_OnPageIndexChanged(object sender, GridViewPageEventArgs e)
    {
        this.GridView3.PageIndex = e.NewPageIndex;
        this.GridView3.DataBind();
    }
}
